package tcts0421;
import java.util.Scanner;
public class 回文子串01 {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int t = sc.nextInt();
            int arr[]=new int[t];
            for (int i = 0; i < t; i++) {
                String s = sc.next();
                int huiwen = isHuiwen(s);
                arr[i] = huiwen;
            }
            for (int i = 0; i < arr.length; i++) {
                System.out.println(arr[i]);
            }
        }
        public static int isHuiwen(String s){
            int l = 0, r = s.length() - 1, ans = 0;
            while (l < r) {
                if (s.charAt(l) == s.charAt(r)) {
                    l++;
                    r--;
                } else {
                    ans++;
                    if (s.charAt(l) == '1') l++;
                    else r--;
                }
            }
            return ans;
        }
}
